package com.example.caorl.job1.conc0302.threadpool;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

@Slf4j
public class ExceptionDemo {
    
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(1);
    
        try {
            Future<Double> future = executorService.submit(() -> {
                //此方式直接抛出异常
                throw new RuntimeException("executorService.submit()");
            });
            double b = future.get();
            System.out.println(b);
            /*executorService.execute(() -> {
                // 此方式在线程池内部捕获并打印
                throw new RuntimeException("executorService.submit()");
            });*/
            
        } catch (Exception ex) {
            System.out.println("catch submit");
            log.error("thread error", ex);
        }
//
//        try {
//            executorService.execute(() -> {
//                  throw new RuntimeException("executorService.execute()");
//                });
//        } catch (Exception ex) {
//            System.out.println("catch execute");
//            ex.printStackTrace();
//        }
//
        executorService.shutdown();
        System.out.println("Main Thread End!");
    }
    
}
